#!/usr/bin/env node

const Router = require('koa-router'),
	comment = require('../models/comment_mod'),
	image = require('../models/image_mod'),
	sj = require('silly-datetime'),
	router = new Router;

router.prefix('/api/comment');

router.post('/', async (ctx, next) => {
console.log(ctx.request.body)
	let time = sj.format(new Date());
	let { commodityco_id, dynamicco_id, userco_id, comment_context } = ctx.request.body;
	if (commodityco_id) {
		let res = await comment.Comment_C(commodityco_id, userco_id, comment_context, time);
		ctx.body = res;
	} else if (dynamicco_id) {
		let res = await comment.Comment_D(dynamicco_id, userco_id, comment_context, time);
		ctx.body = res;
	}
})
router.delete('/', async (ctx, next) => {
	let { comment_id } = ctx.request.body;
	let res = await comment.Comment_delete(comment_id);
	ctx.body = res;
})
router.post('/comment', async (ctx, next) => {
	let { userco_id } = ctx.request.body;
	let res = await comment.Comment_get(userco_id);
	ctx.body = res;
})
router.post('/getlist', async (ctx, next) => {
	let { commodity_id } = ctx.request.body;
	let res = await comment.Comment_get_commodity(commodity_id);
	ctx.body = res;
})
router.post('/getlist2', async (ctx, next) => {
	let { dynamic_id } = ctx.request.body;
	let res = await comment.Comment_get_dynamic(dynamic_id);
	ctx.body = res;
})
module.exports = router;
